package com.zeta.plan.advice;

import com.zeta.plan.model.ResponseResult;
import com.zeta.plan.exception.AuthenticationException;
import com.zeta.plan.exception.DuplicationUsernameException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler {

    /**
     * 用户名重复异常
     * @param e
     * @return
     */
    @ExceptionHandler(DuplicationUsernameException.class)
    public ResponseResult<Void> duplicationUsernameExceptionHandler(Exception e) {
        return ResponseResult.error().setMessage(e.getMessage());
    }

    /**
     * 认证异常
     * @param e
     * @return
     */
    @ExceptionHandler(AuthenticationException.class)
    public ResponseResult<Void> authenticationExceptionHandler(Exception e) {
        return ResponseResult.unauthorized().setMessage(e.getMessage());
    }
}
